﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using MOJsdk;

namespace MOJ
{
    /// <summary>
    /// Interaction logic for Win_UserOption.xaml
    /// </summary>
    public partial class Win_UserOption : Window
    {
        private Dictionary<string, int> _options;
        private string selection;

        public Win_UserOption(string WinTitle, string[] Options)
        {
            InitializeComponent();

            _options = new Dictionary<string, int>();
            for (int i = 0; i < Options.Length; i++)
                _options.Add(Options[i], i);

            this.Title = WinTitle;

            INI();
        }

        private void INI()
        {
            selection = null;
            this.Height = 70 + (_options.Count * 20);

            this.MinHeight = this.Height;
            this.MinWidth = 300;

            INIStyle();

            foreach (var v in _options)
            {
                RadioButton btn = new RadioButton();
                btn.Content = v.Key;
                btn.ApplyStyle("0101168");
                btn.Checked += delegate { selection = btn.Content.ToString(); };
                _Panel.Children.Add(btn);
            }

            _btn.Click += ButtonClicked;
            this.Closing += IsClosing;
        }
        private void INIStyle()
        {
            _Grid.ApplyStyle("0101166");
            _btn.ApplyStyle("0101167");
            _Panel.ApplyStyle("0101169");
        }

        public int Result
        {
            get
            {
                if (selection == null)
                    return -1;

                return _options[selection];
            }
        }
        private void ButtonClicked(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }
        private void IsClosing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (selection == null)
                e.Cancel = true;
        }
    }
}
